import { Body, Controller, HttpStatus, Logger, Get } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
// @app
import {
  BaseApiErrorResponse,
  SwaggerBaseApiResponse,
  AuthPermissions,
  EmptyResponseType,
  IRequestUser,
} from '@app/common';
// service
import { UserService } from './user.service';

@ApiTags('user')
@ApiBearerAuth()
@Controller('user')
export class UserController {
  // logger
  readonly logger = new Logger(UserController.name);

  constructor(private readonly userService: UserService) {}

  @Get('info')
  @ApiBearerAuth()
  @ApiOperation({
    summary: '获取登录用户信息接口',
  })
  @ApiResponse({
    status: HttpStatus.OK,
    // type: SwaggerBaseApiResponse(LoginOutputDto),
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    type: BaseApiErrorResponse,
  })
  async user(@IRequestUser user: any): Promise<any> {
    return await this.userService.getUserWithAuthorities(user);
  }

  @Get('list')
  @ApiOperation({
    summary: '管理员列表接口',
  })
  @ApiResponse({
    status: HttpStatus.OK,
    type: SwaggerBaseApiResponse(EmptyResponseType),
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    type: BaseApiErrorResponse,
  })
  @AuthPermissions('system:user:list')
  async list(@Body() userQueryDto: any): Promise<any> {
    this.logger.log(userQueryDto, 'userQueryDto');
    return userQueryDto;
  }
}
